package hotel.controller;

import java.util.Map;

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import hotel.entity.Reserve;
import hotel.entity.Room;
import hotel.entity.Sales;
import hotel.entity.SalesLineItem;
import hotel.entity.User;
import hotel.service.IReserveService;
import hotel.service.IRoomService;
import hotel.service.ISalesLineItemService;
import hotel.service.ISalesService;
import hotel.service.IUserService;
import util.JSONUtil;
import util.StringUtil;

/**
 * Index控制器@Controller
 * @Valid 校验
 * 获取session方法public  String getUser（HttpSession httpSession
 * 其他参数model.addAttribute("username", "123456");
 */
@Controller
public class IndexController {

	private static Logger log=Logger.getLogger(IndexController.class);
	@Autowired
	IReserveService<Reserve> reserveService;
	@Autowired
	ISalesService<Sales> salesService;
	@Autowired
	ISalesLineItemService<SalesLineItem> itemService;
	@Autowired
	IRoomService<Room> roomService;
	@Autowired
	IUserService<User> userService;
	
	@RequestMapping(value = "index")
	public String index(Model model) {
		model.addAttribute("reserve_count", reserveService.getReserveCount());
		model.addAttribute("sales_count", salesService.getTotalSale());
		model.addAttribute("person_count", itemService.getCheckinCustomerCount());
		model.addAttribute("room_count", roomService.getAvailableCount());
		model.addAttribute("roomStatistic", JSONUtil.roomStatisticsToJson(roomService.getRoomStatistics()));
		model.addAttribute("user_count", userService.getTotalCount("User"));
		
		Map<String,Double> map=salesService.getSaleStatistic();
		model.addAttribute("categories", StringUtil.getSalesCategories(map));
		model.addAttribute("data", StringUtil.getSalesDate(map));
		log.info("IndexController");
		return "index";
	}
}
